package com.terana.lbs.marketing.web.mapper;

import com.tarena.lbs.pojo.marketing.dos.UserReceiveCouponDO;
import com.tarena.lbs.pojo.marketing.query.UserCouponQuery;
import org.apache.ibatis.annotations.*;

import java.util.List;
@Mapper
public interface UserReceiveCouponMapper {
    @Select("select * from user_receive_coupon " +
            "where user_id=#{userId} and coupon_id=#{couponId}")
    List<UserReceiveCouponDO> selectReceiveRecordsByUserIdAndCouponId(@Param("userId") Integer userId,@Param("couponId") Integer couponId);

    @Insert({
            "INSERT INTO user_receive_coupon (",
            "       user_id,",
            "       coupon_id,",
            "       receive_channel,",
            "       status,",
            "       create_at,",
            "       update_at,",
            "       activity_id,",
            "       coupon_code,",
            "       order_no,",
            "       used_time,",
            "       coupon_type,",
            "       coupon_value,",
            "       shop_id)",
            "VALUES (",
            "       #{userId},",
            "       #{couponId},",
            "       #{receiveChannel},",
            "       #{status},",
            "       #{createAt},",
            "       #{updateAt},",
            "       #{activityId},",
            "       #{couponCode},",
            "       #{orderNo},",
            "       #{usedTime},",
            "       #{couponType},",
            "       #{couponValue},",
            "       #{shopId})"
    })
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    void insert(UserReceiveCouponDO aDo);

    @Select("select * from user_receive_coupon where user_id=#{userId} and status=#{status}")
    List<UserReceiveCouponDO> selectReceiveRecordsByUserId(UserCouponQuery query);

    @Select("select * from user_receive_coupon where coupon_code=#{couponCode}")
    UserReceiveCouponDO selectRecevieRecordsByCode(String couponCode);
}
